<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
    <head>
        <title>仓位管理</title>
    </head>
    <body>
        <div id="positionGrid" style="height:580px;" class="x-form-item">
        </div>
        <script>
            /*
             * Ext JS Library 2.1
             * Copyright(c) 2006-2008, Ext JS, LLC.
             * licensing@extjs.com
             *
             * http://extjs.com/license
             */
            Ext.onReady(function(){
                var fm = Ext.form;
                var positionCM = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(), {
                    header: '编号',
                    dataIndex: 'id'
                }, {
                    header: '航空公司',
                    dataIndex: 'airways_name'
                }, {
                    header: '仓位代码',
                    dataIndex: 'position_code',
                    editor: new fm.TextField({
                        allowBlank: false
                    })
                }, {
                    header: '折扣',
                    dataIndex: 'discount',
                    editor: new fm.TextField({
                        allowBlank: false
                    })
                }]);
                //隐藏系统编号
                positionCM.setHidden(1, !positionCM.isHidden(1));
                positionCM.defaultSortable = true;
                var positionDS = new Ext.data.Store({
                    proxy: new Ext.data.HttpProxy({
                        url: '/admin/getAllPositions'
                    }),
                    reader: new Ext.data.JsonReader({
                        totalProperty: 'totalProperty',
                        root: 'root'
                    }, [{
                        name: 'id'
                    }, {
                        name: 'airways_name',
                        mapping: 'airways.airways_name'
                    }, {
                        name: 'position_code'
                    }, {
                        name: 'discount'
                    }])
                });
                /************************************************************
                 * Define menubar now in here
                 *   add and delete functions
                 ************************************************************/
                var menubar = [{
                    text: '增加仓位',
                    tooltip: '增加仓位',
                    iconCls: 'addItem',
                    handler: function(){
                        // add new costlevel now - action
                        CreatePosition(positionDS);
                    }
                }, '-', {
                    text: '删除仓位',
                    tooltip: '删除仓位',
                    iconCls: 'remove',
                    handler: function(){
                        // delete costlevel now - action
                        DeletePosition(positionDS, positionGridPanel);
                    }
                }, //				'-', {
                //                    text: '编辑仓位',
                //                    tooltip: '编辑仓位',
                //                    iconCls: 'editItem',
                //                    handler: function(){
                //                        // delete costlevel now - action
                //                        EditPosition(positionDS, positionGridPanel);
                //                    }
                //                },
                '-', {
                    text: '保存修改',
                    tooltip: '保存修改',
                    iconCls: 'save',
                    handler: function(){
                        // delete costlevel now - action
                        SavePosition(positionDS, positionGridPanel);
                    }
                }];
                var positionGridPanel = new Ext.grid.EditorGridPanel({
                    el: 'positionGrid',
                    ds: positionDS,
                    cm: positionCM,
                    collapsible: true,
                    animCollapse: false,
                    title: '仓位列表:',
                    tbar: menubar,
                    loadMask: true,
                    clicksToEdit: 1
                });
                positionGridPanel.render();
                //ds.load();
                positionDS.load();
                //-------------------------------------------------------------------
                
            });
        </script>
    </body>
</html>
